﻿using System;

namespace Lesson17_练习题
{
    #region 练习一
    //真的鸭子嘎嘎叫 木头鸭子吱吱叫 橡皮鸭子唧唧叫
    class Duck
    {
        public virtual void Speak() { }
    }
    class RealDuck : Duck
    {
        public override void Speak()
        {
            Console.WriteLine("嘎嘎");
        }
    }
    class WoodenDuck : Duck
    {
        public override void Speak()
        {
            Console.WriteLine("吱吱");
        }
    }
    class RubberDuck : Duck
    {
        public override void Speak()
        {
            Console.WriteLine("唧唧");
        }
    }
    #endregion

    #region 练习二
    class Figure
    {
        public virtual float GetArea()
        {
            return 0;
        }
        public virtual float GetPerimeter()
        {
            return 0;
        }
    }
    class Rectangle : Figure
    {
        private float l;
        private float w;
        public Rectangle(float l, float w)
        {
            this.l = l;
            this.w = w;
        }
        public override float GetArea()
        {
            return l * w;
        }
        public override float GetPerimeter()
        {
            return (2 * l) + (2 * w);
        }
    }
    class Square : Figure
    {
        private int a;
        public Square(int a)
        {
            this.a = a;
        }
        public override float GetArea()
        {
            return a * a;
        }
        public override float GetPerimeter()
        {
            return 4 * a;
        }
    }
    class Circle : Figure
    {
        private float r;
        private const float PI = 3.14f;
        public Circle(float r)
        {
            this.r = r;
        }

        public override float GetArea()
        {
            return PI * r * r;
        }
        public override float GetPerimeter()
        {
            return 2 * PI * r;
        }
    }
    #endregion
    class Program
    {
        static void Main(string[] args)
        {
            #region 练习一
            Duck rd = new RealDuck();
            rd.Speak();
            Duck wd = new WoodenDuck();
            wd.Speak();
            Duck rud = new RubberDuck();
            rud.Speak();
            #endregion

            #region 练习二
            Figure r = new Rectangle(2, 3);
            Console.WriteLine(r.GetArea());
            Console.WriteLine(r.GetPerimeter());

            Figure s = new Square(2);
            Console.WriteLine(s.GetArea());
            Console.WriteLine(s.GetPerimeter());
            
            Figure c = new Circle(2);
            Console.WriteLine(c.GetArea());
            Console.WriteLine(c.GetPerimeter());
            #endregion
        }
    }
}